local huishi = fk.CreateSkill{
    name = "jinhs__huishi",
}

Fk:loadTranslationTable{
   ["jinhs__huishi"] = "慧识",
   [":jinhs__huishi"] = "摸牌阶段，你可以改为观看牌堆顶的X张牌，获得其中的一半(向上取整)，然后将其余牌置入牌堆底（X为场上未确定势力的角色数）。",

   ["#jinhs__huishi-invoke"] = "慧识：你可以放弃摸牌，改为观看牌堆顶%arg张牌并获得其中的一半，其余置于牌堆底",

   ["$jinhs__huishi1"] = "你的想法，我已知晓。",
   ["$jinhs__huishi2"] = "妾身慧眼，已看透太多。",
}

huishi:addEffect(fk.EventPhaseStart,{
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
      local n = #table.filter(player.room.alive_players, function(p) return p.kingdom == "unknown" end)
      return target == player and player:hasSkill(huishi.name) and player.phase == Player.Draw and n > 0
    end,
    on_cost = function(self, event, target, player, data)
      local n = #table.filter(player.room.alive_players, function(p) return p.kingdom == "unknown" end)
      if n == 0 then return false end
      return player.room:askToSkillInvoke(player, {skill_name = huishi.name, prompt = "#jinhs__huishi-invoke:::"..n})
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      data.phase_end = true
      local x = #table.filter(player.room.alive_players, function(p) return p.kingdom == "unknown" end)
      if x == 0 then return true end
      local cards = room:getNCards(x)
      local y = math.ceil(x / 2)
      local result = room:askToGuanxing(player,{
        cards = cards,
        top_limit = {x-y, x},
        bottom_limit = {y, y},
        skill_name = huishi.name,
        skip = true,
        area_names = {"Bottom", "toObtain"},
      })
      room:moveCardTo(result.bottom, Player.Hand, player, fk.ReasonPrey, huishi.name, "", false, player)
      room:moveCards {
      ids = result.top,
      toArea = Card.DrawPile,
      moveReason = fk.ReasonJustMove,
      skillName = huishi.name,
      proposer = player,
      moveVisible = false,
      visiblePlayers = player,
      drawPilePosition = -1,
    }
    end,
})

return huishi